package my.jwds.p48;

import java.util.Arrays;

public class Rotate {
    public static void main(String[] args) {
        Rotate obj = new Rotate();
        int[][] matrix = {
                {126,96 ,126,0  ,42 ,128,3  ,0  ,111,-1 ,66 ,37},
                {123,57 ,130,22 ,-1 ,12 ,53 ,40 ,106,57 ,51 ,20},
                {112,104,80 ,12 ,137,116,88 ,136,85 ,71 ,137,129},
                {56 ,13 ,2  ,41 ,13 ,70 ,79 ,137,0  ,83 ,32 ,16},
                {96 ,103,74 ,75 ,17 ,142,112,2  ,104,49 ,15 ,98},
                {22 ,105,91 ,109,49 ,102,111,123,116,114,21 ,131},
                {57 ,117,141,59 ,57 ,31 ,92 ,26 ,135,23 ,102,25},
                {39 ,72 ,44 ,0  ,122,61 ,115,18 ,39 ,79 ,128,89},
                {38 ,112,69 ,12 ,83 ,91 ,16 ,14 ,82 ,14 ,90 ,140},
                {62 ,39 ,40 ,70 ,80 ,-1 ,112,120,88 ,14 ,137,84},
                {76 ,109,103,116,45 ,104,78 ,101,73 ,21 ,130,29},
                {129,3  ,44 ,68 ,18 ,135,66 ,98 ,32 ,107,25 ,129}
        };
        obj.rotate(matrix);
        for (int[] ints : matrix) {
            System.out.println(Arrays.toString(ints));
        }
        System.out.println();
    }
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        Integer [][] temp = new Integer[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                temp[i][j] = matrix[i][j];
                if (temp[n-j-1][i] != null){
                    matrix[i][j] = temp[n-j-1][i];
                }else{
                    matrix[i][j] = matrix[n-j-1][i];
                }
            }
        }
    }
}
